<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml">
    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width-device-width, initial-scale=1.0" />
        <title>博客管理</title>
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/semantic-ui/2.2.10/semantic.min.css">
        <link th:href="@{../css/me.css}" rel="stylesheet" type="text/css" href="../../static/css/me.css">
    </head>
    <body>
        <!-- 导航 -->
        <nav class="ui inverted attached segment m-padded-tb-mini m-shadow-small">
            <div class="ui container">
                <div class="ui inverted secondary stackable menu">
                    <h2 class="ui teal header item">管理后台</h2>
                    <a th:href="@{/admin/blogManage}" href="#" class="active m-item item m-mobile-hide"><i class="mini sticky note icon"></i>博客</a>
                    <a th:href="@{/admin/typeManage}" href="#" class="m-item item m-mobile-hide"><i class="mini idea icon"></i>分类</a>
                    <a th:href="@{/admin/tagManage}" href="#" class="m-item item m-mobile-hide"><i class="mini tags icon"></i>标签</a>

                    <!-- 右边头像菜单 -->
                    <div class="right m-item menu m-mobile-hide">
                        <div class="ui dropdown item">
                            <div class="text">
                                <img th:src="@{${session.user.avatar}}" class="ui avatar image" src="../../static/img/qibao.jpg" >
                                <span th:text="${session.user.nickname}">*听雨*</span>
                            </div>
                            <i class="dropdown icon"></i>
                            <div class="menu">
                                <a th:href="@{/admin/logout}" href="#" class="item">注销</a>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
            <a href="#" class="ui menu toggle black icon button m-right-top m-mobile-show">
                <i class="sidebar icon"></i>
            </a>
        </nav>
        
        <!-- 二级导航 -->
        <div class="ui attached pointing menu">
            <div class="ui container">
                <div class="right menu">
                    <a th:href="@{/admin/blogPublish}" href="#" class="item">发布</a>
                    <a th:href="@{/admin/blogManage}" href="#" class="teal active item">列表</a>
                </div>
            </div>
        </div>
        
        
        <!-- 中间内容 -->
        <div class="m-container-small m-padded-tb-large">
            <div class="ui container">
                <!--消息提示-->
                <div class="ui success message" th:unless="${#strings.isEmpty(message)}">
                    <i class="close icon"></i>
                    <div class="header">提示：</div>
                    <p th:text="${message}">恭喜，添加成功！</p>
                </div>

                <!-- 查询表单 -->
                <div class="ui secondary segment form">
                    <input type="hidden" name="page">
                    <div class="inline fields">
                        <!-- 标题查询框 -->
                        <div class="field">
                            <input type="text" name="title" placeholder="标题" />
                        </div>
                        <div class="ui labeled action input">
                            <!-- 分类选择框 -->
                            <div class="field">
                                <div class="ui type selection dropdown">
                                    <input type="hidden" name="typeId" />
                                    <i class="dropdown icon"></i>
                                    <div class="default text">分类</div>
                                    <div class="menu">
                                        <!--<div class="item" data-value="-1">查询全部</div>-->
                                        <div th:each="type : ${types}" class="item" data-value="0" th:data-value="${type.id}"  th:text="${type.name}">C#</div>
                                        <!--/*-->
                                        <div class="item" data-value="1">java</div>
                                        <div class="item" data-value="2">python</div>
                                        <!--*/-->
                                    </div>
                                </div>
                            </div>
                            <!--清除-->
                            <button id="clear-btn" class="ui compact clear button">清除</button>
                        </div>

                        <!-- 是否推荐 -->
                        <div class="field">
                            <div class="ui checkbox">
                                <input type="checkbox" name="recommend" id="recommend" />
                                <label for="recommend">推荐</label>
                            </div>
                        </div>
                        <!-- 搜索按钮 -->
                        <div class="field">
                            <button type="button" id="search-btn" class="ui mini teal basic button"><i class="search icon"></i>搜索</button>
                        </div>
                    </div>
                </div>

                <div id="table-containe">
                    <!-- 搜索结果表格 -->
                    <table class="ui compact celled teal table"  th:fragment="blogList">
                        <thead>
                        <tr>
                            <th>序号</th>
                            <th>标题</th>
                            <th>类型</th>
                            <th>推荐</th>
                            <th>状态</th>
                            <th>更新时间</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr th:each="blog,iterStat : ${page.content}">
                            <td th:text="${iterStat.count}">1</td>
                            <td th:text="${blog.title}">刻意练习的清单</td>
                            <td th:text="${blog.type.name}">认知升级</td>
                            <td th:text="${blog.recommend} ? '是':'否'">是</td>
                            <td th:text="${blog.published} ? '发布':'草稿'">发布</td>
                            <td th:text="${blog.updateTime}">2020年1月12日 23:01:03</td>
                            <td>
                                <a th:href="@{/admin/blogManage/{id}/edit(id=${blog.id})}" href="" class="ui mini teal button">编辑</a>
                                <a th:href="@{/admin/blogManage/{id}/delete(id=${blog.id})}" href="" class="ui mini red button">删除</a>
                            </td>
                        </tr>
                        </tbody>
                        <tfoot>
                        <tr>
                            <th colspan="7">
                                <div class="ui mini pagination menu" th:if="${page.totalPages}>1">
                                    <a onclick="page(this)" th:attr="data-page=${page.number}-1" class="item" th:unless="${page.first}">上一页</a>
                                    <a onclick="page(this)" th:attr="data-page=${page.number}+1" class="item" th:unless="${page.last}">下一页</a>
                                </div>
                                <a href=""  th:href="@{/admin/blogPublish}" class="ui mini right floated teal button">添加</a>
                            </th>
                        </tr>
                        </tfoot>
                    </table>

                </div>

            </div>
        </div>

        <br />

        <!-- 底部footer -->
        <footer class="ui inverted vertical segment m-padded-tb-massive">
            <div class="ui center aligned container">
                <div class="ui inverted divided stackable grid">
                    <!-- 左边图片 -->
                    <div class="three wide column">
                        <div class="ui inverted link list">
                            <img th:src="@{../img/spring_boot.jpg}" src="../../static/img/spring_boot.jpg"  class="ui rounded image" style="width: 100px;">
                        </div>
                    </div>
                    <!-- 友链 -->
                    <div class="three wide column">
                        <h4 class="ui inverted header m-text-spaced m-opacity-mini">友链</h4>
                        <div class="ui inverted link list">
                            <a href="#" class="item m-opacity-mini">听雨1</a>
                            <a href="#" class="item m-opacity-mini">听雨2</a>
                            <a href="#" class="item m-opacity-mini">听雨3</a>
                        </div>
                    </div>
                    <!-- 联系我 -->
                    <div class="three wide column">
                        <h4 class="ui inverted header m-text-spaced m-opacity-mini">联系我</h4>
                        <div class="ui inverted link list">
                            <p class="item m-opacity-mini">Email : ygf751@163.com</p>
                                <p class="item m-opacity-mini">QQ : 1186472484</p>
                        </div>
                    </div>
                    <!-- 关于博客 -->
                    <div class="seven wide column">
                        <h4 class="ui inverted header m-text-spaced m-opacity-mini">关于</h4>
                        <div class="ui inverted link list">
                            <p class="item m-text-thin m-text-spaced m-opacity-mini">这是我的个人博客，会分享编程、Linux、mac
                                os相关内容，希望能给大家带来帮助。</p>
                        </div>
                    </div>
                </div>
                <!-- 横线 -->
                <div class="ui inverted section divider"></div>
                <!-- 版权 -->
                <p class="m-text-thin m-text-spaced m-opacity-tiny">copyright © 2020 - 2022 asdfghjkl</p>
            </div>
        </footer>


        <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
        <script src="https://cdn.jsdelivr.net/semantic-ui/2.2.10/semantic.min.js"></script>

        <script>
            $('.menu.toggle').click(function() {
                $('.m-item').toggleClass('m-mobile-hide');
            });
            $(".ui.dropdown").dropdown({
                on: "hover"
            });

            //给隐藏的page input赋值
            function page(obj) {
                $("[name='page']").val($(obj).data("page"));
                loaddata();
            }

            //搜索按钮事件
            $("#search-btn").click(function () {
                $("[name='page']").val(0);  //清零page
                loaddata();
            })

            //ajax请求加载数据
            function loaddata() {
                $("#table-containe").load(/*[[@{/admin/blogManage/search}]]*/"/admin/blogManage/search",{
                    title : $("[name='title']").val(),
                    typeId : $("[name='typeId']").val(),
                    recommend : $("[name='recommend']").prop('checked'),
                    page : $("[name='page']").val()
                });
            }

            //操作提示关闭
            $(".message .close").on("click",function () {
                $(this).closest(".message").transition("fade");
            });


            //清除分类组合框
            $('#clear-btn')
                .on('click', function() {
                    $('.ui.type.dropdown')
                        .dropdown('clear')
                    ;
                })
            ;
        </script>
    </body>
</html>
